/**
 * File		: Vector2.java
 * Subject	: Represents a vector with two coordinates
 * Author	: Isaac Parenteau (locus2k@gmail.com)
 * Date		: May 3rd, 2011
 */
package opengameflow.framework.vector;

public class Vector2 {
	
	public static final String TAG = Vector2.class.getCanonicalName();
	
	private float x;
	private float y;
	
	/**
	 * Default Constructor
	 */
	public Vector2(){
		this(0, 0);
	}
	
	/**
	 * Constructor
	 * @param x X coordinate
	 * @param y Y coordinate
	 */
	public Vector2(float x, float y){
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Gets the distance between
	 * @param other
	 * @return
	 */
	public float distance(Vector2 other){
		float xDif = x - other.getX();
		float yDif = y - other.getY();
		
		xDif *= xDif;
		yDif *= yDif;
		
		float distance = (float) Math.sqrt(xDif + yDif);
		
		return distance;
	}
	
	/**
	 * Normalizes the vector with another vector
	 * @param other
	 * @return normalized vector
	 */
	public Vector2 normalize(Vector2 other){
		float distance = distance(other);
		
		float xDist = this.x / distance;
		float yDist = this.y / distance;
		
		return new Vector2(xDist, yDist);
	}
	
	/**
	 * Adds a vector to the current vector and returns 
	 * a new vector with the added values
	 * @param other vector to add
	 * @return new vector with the values
	 */
	public Vector2 add(Vector2 other){
		return new Vector2(this.x + other.getX(), 
				this.y + other.getY());
	}
	
	/**
	 * Adds another vector with the current one
	 * @param other other vector to add
	 */
	public void addVector(Vector2 other){
		this.x += other.getX();
		this.y += other.getY();
	}
	
	public float getX() { return this.x; }
	public void setX(float x) { this.x = x; } 
	public float getY() { return this.y; }
	public void setY(float y) { this.y = y; }
	
	
	public static Vector2 Up = new Vector2(0,1);
	public static Vector2 Zero = new Vector2(0,0);

	public boolean equals(Vector2 other) {
		return (this.x == other.getX() && this.y == other.getY());
	}
}
